/**
 * 校准
 */

import { ConfigProvider, message, Modal, Spin } from "antd";
import { FC, useState } from "react";
import { getKshStartCalibration } from "../../api";
import { useWindowFontSize } from "../../../../assets/fun/Antd/configprovider";
import { JiaozhunZhunbeiBox } from "./style";


const ModuleJiaozun: FC<{
  open: boolean;
  id: React.Key;
  geiliaoji: number;
  handleCallback: () => void;
}> = ({ open, id, geiliaoji, handleCallback }) => {
  const [jiaozhunButtonLoading, setjiaozhunButtonLoading] = useState(false); // 校准加载中

  const handleCancel = () => {
    handleCallback();
  };
  // 开始校准
  const handleKaishiJiaozhunClick = async () => {
    setjiaozhunButtonLoading(true);
    const { code, msg } = (await getKshStartCalibration({
      id: id,
      number: geiliaoji,
    })) as {
      code: number;
      msg: string;
    };
    if (code === 20000) {
      message.success("校准成功");
      handleCallback();
    } else {
      message.error(msg);
    }
    setjiaozhunButtonLoading(false);
  }
  return (
    <ConfigProvider
      theme={{
        components: {
         
        },
      }}
    >
      <Modal
        title="皮带秤校准1"
        closable={{ "aria-label": "Custom Close Button" }}
        open={open}
        className="jiaozunZhunbei"
        getContainer={false}
        onCancel={handleCancel}
        footer={null}
        width={useWindowFontSize(760)}
      >
        <Spin spinning={jiaozhunButtonLoading} >

          <JiaozhunZhunbeiBox >
          <div className="jiaozunZhunbei_title"  onClick={() => handleKaishiJiaozhunClick()}></div>
          <div className="jiaozunZhunbei_content">
            <div className="jiaozunZhunbei_content_icon"></div>
            <div>提示：执行该操作后的一次装车，只会开启当前给料机运行，请牢记拉煤车牌号并人工放料！</div>
          </div>
        </JiaozhunZhunbeiBox>
        </Spin>
        
      </Modal>
    </ConfigProvider>
  );
};

export default ModuleJiaozun;
